﻿Public Class clMapa
    Public Event Aparicion_Monstruos(ByVal sender As clMapa, ByVal e As EventArgs)
    Public CasillasMapa(,) As clCasilla = {{}, {}}
    Private Const lado As Byte = 48
    Private Y As Integer
    Private X As Integer

    Public ReadOnly Property LargoCasillas As Integer
        Get
            Return X * 48
        End Get
    End Property
    Public ReadOnly Property AltoCasilla As Integer
        Get
            Return Y * 48
        End Get
    End Property
    Public Sub New(ByVal CasillasHorizontales As Integer, ByVal CasillasVerticales As Integer)
        ReDim CasillasMapa(CasillasVerticales - 1, CasillasHorizontales - 1)
        Y = (CasillasVerticales)
        X = (CasillasHorizontales)
    End Sub

    Public Function AñadirCasilla(ByRef casilla As clCasilla, ByVal DondeX As Integer, ByVal DondeY As Integer) As String

        casilla.Control.Location = New Point((DondeX * lado), (DondeY * lado))
        Try
            CasillasMapa(DondeX, DondeY) = casilla
            Return "Todo en orden"
        Catch ex As Exception
            Return ex.Message
        End Try
    End Function

    ''' <summary>
    ''' Valida el acceso a un determinado lugar a un control.
    ''' </summary>
    ''' <param name="coordenadaX">Cordenada x a la que accede</param>
    ''' <param name="coordeandadY">Coordenada y a la que accede</param>
    ''' <param name="heroe"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ValidarAccesoAEn(ByVal coordenadaX As Integer, ByVal coordeandadY As Integer, ByVal heroe As clControlBasico) As Boolean
        Try
            If Not CasillasMapa(coordenadaX, coordeandadY).Suelo.ToString.Contains("Inaccesible") Then Return True
            Return False
        Catch ex As Exception
            Return False 'Esto sucederá cuando quiera salirse del mapa, salirse del mapa es como ir a una zona inaccesible. 
        End Try
    End Function
    Private Sub QuitarNothing(ByVal x As Integer, ByVal y As Integer)
        If CasillasMapa(x, y) Is Nothing Then
            Dim foto As New PictureBox
            foto.Size = New Point(lado, lado)
            foto.Location = New Point(x * lado, y * lado)
            foto.Visible = True
            foto.Enabled = True
            Dim tierra As New clCasillaTierra(foto)
            CasillasMapa(x, y) = tierra
        End If
    End Sub
    Public Sub AgregarMapa(ByRef C As Form)
        For Miy = 0 To (Y - 1)
            For Mix = 0 To (X - 1)
                QuitarNothing(Mix, Miy)
                C.Controls.Add(CasillasMapa(Mix, Miy).Control)
            Next
        Next
    End Sub
    Public Sub aparecer()
        RaiseEvent Aparicion_Monstruos(Me, New EventArgs)

    End Sub
End Class
